<?php
   class Model_hotelroom extends CI_Model{
		protected $_table = "tbl_hotelroom";
		public function __construct(){
			parent::__construct();
			$this->load->database();
		}
		public function getdata($id){
			$this->db->where("id",$id);
			return $this->db->get($this->_table)->row_array();
		}
		
		public function getall_column($column){
			$this->db->select($column);
			return $this->db->get($this->_table)->result_array();
		}
		
		public function listall($limit,$start){
			return $this->db->get($this->_table)->result_array();
		}
		
		public function add($data){
        	$this->db->insert($this->_table,$data);
		}
		public function del($id){
			$this->db->where("id",$id);
			$this->db->delete($this->_table);
		}
		public function update($data,$id){
			$this->db->where("id",$id);
			$this->db->update($this->_table,$data);
		}
		
		
		//public function listallbyid($limit,$start,$id){
//			$this->db->where("hotelid",$id);	
//			$this->db->limit($limit,$start);
//			return $this->db->get($this->_table)->result_array();
//		}
//		
//		public function listallbyhotelname_limit($limit,$start,$name){
//			$query=$this->db->query("SELECT a.* FROM `tbl_hotelroom` as a inner join tbl_hotel as b on a.hotelid=b.id where b.name like '%".$name."%' limit ".$start.",".$limit);			
//			return $query->result_array();
//		}
//		
		
//		
//		public function countroombyhotelid($id){
//			$query=$this->db->query("SELECT count(*) as total FROM `tbl_hotelroom` WHERE id=".$id);	
//			return $query->row_array();
//		}

		//used
		public function getallroombyhoteid($hotelid){
			$query=$this->db->query("select * from tbl_hotelroom where hotelid=".$hotelid);
			return $query->result_array();
		}
		public function getbyhotelid($idhotel,$from){
			$query=$this->db->query("SELECT *,(select price from tbl_hotelroomprice where roomid in (h.id) and fromdate<='".$from."' and todate>='".$from."' order by price limit 0,1) as minprice,(select oldprice from tbl_hotelroomprice where roomid in (h.id) and fromdate<='".$from."' and todate>='".$from."' order by price limit 0,1) as oldprice,(select extra from tbl_hotelroomprice where roomid in (h.id) and fromdate<='".$from."' and todate>='".$from."' order by price limit 0,1) as extra FROM `tbl_hotelroom` as h where h.hotelid=".$idhotel);
			return $query->result_array();
		}
	}